//
//  YJBTradeMarketTableViewCell.m
//  YunJiaBaoFirst
//
//  Created by 腾云小白龍 on 16/7/28.
//  Copyright © 2016年 腾云小白龍. All rights reserved.
//

#import "YJBTradeMarketTableViewCell.h"
@interface YJBTradeMarketTableViewCell()
@property (strong, nonatomic) UILabel * nameLabel;
@property (strong, nonatomic) UILabel * codeLabel;
@property (strong, nonatomic) UILabel * nowPriceLabel;
@property (strong, nonatomic) UILabel * nowCountLabel;
@property (strong, nonatomic) UILabel * buyPriceLabel;
@property (strong, nonatomic) UILabel * buyCountLabel;
@property (strong, nonatomic) UILabel * sellPriceLabel;
@property (strong, nonatomic) UILabel * sellCountLabel;
@property (strong, nonatomic) UILabel * percentLabel;

@end

@implementation YJBTradeMarketTableViewCell
#define fontSize 14
- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *reusedID = @"YJB";
    YJBTradeMarketTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusedID];
    if (cell==nil) {
        cell = [[YJBTradeMarketTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusedID];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.font = [UIFont systemFontOfSize:fontSize-2];
        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        self.nameLabel.textColor = [UIColor blackColor];
        self.nameLabel.numberOfLines = 0;
        [self addSubview:self.nameLabel];
        
        UILabel * codeLabel = [[UILabel alloc] init];
        self.codeLabel = codeLabel;
        self.codeLabel.font = [UIFont systemFontOfSize:fontSize -2];
        self.codeLabel.textColor = [UIColor grayColor];
        self.codeLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:codeLabel];
        
        UILabel * nowPriceLabel = [[UILabel alloc] init];
        self.nowPriceLabel = nowPriceLabel;
        self.nowPriceLabel.textColor = [UIColor blackColor];
        self.nowPriceLabel.font = [UIFont systemFontOfSize:fontSize];
        self.nowPriceLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:nowPriceLabel];
        
        UILabel * nowCountLabel = [[UILabel alloc] init];
        self.nowCountLabel = nowCountLabel;
        self.nowCountLabel.textColor = [UIColor grayColor];
        self.nowCountLabel.textAlignment = NSTextAlignmentCenter;
        self.nowCountLabel.font = [UIFont systemFontOfSize:fontSize];
        [self addSubview:nowCountLabel];
        
        UILabel * buyPriceLabel = [[UILabel alloc] init];
        self.buyPriceLabel = buyPriceLabel;
        self.buyPriceLabel.textColor = [UIColor blackColor];
        self.buyPriceLabel.textAlignment = NSTextAlignmentCenter;
        self.buyPriceLabel.font = [UIFont systemFontOfSize:fontSize];
        [self addSubview:buyPriceLabel];
        
        UILabel * buyCountLabel = [[UILabel alloc] init];
        self.buyCountLabel = buyCountLabel;
        self.buyCountLabel.textAlignment = NSTextAlignmentCenter;
        self.buyCountLabel.textColor = [UIColor grayColor];
        self.buyCountLabel.font = [UIFont systemFontOfSize:fontSize];
        [self addSubview:buyCountLabel];
        
        UILabel * sellPriceLabel = [[UILabel alloc] init];
        self.sellPriceLabel = sellPriceLabel;
        self.sellPriceLabel.textAlignment = NSTextAlignmentCenter;
        self.sellPriceLabel.textColor = [UIColor blackColor];
        self.sellPriceLabel.font = [UIFont systemFontOfSize:fontSize];
        [self addSubview:sellPriceLabel];
        
        UILabel * sellCountLabel = [[UILabel alloc] init];
        self.sellCountLabel = sellCountLabel;
        self.sellCountLabel.textAlignment = NSTextAlignmentCenter;
        self.sellCountLabel.textColor = [UIColor grayColor];
        self.sellCountLabel.font = [UIFont systemFontOfSize:fontSize];
        [self addSubview:sellCountLabel];
        
        UILabel * percentLabel = [[UILabel alloc] init];
        self.percentLabel = percentLabel;
        self.percentLabel.textAlignment = NSTextAlignmentCenter;
        self.percentLabel.textColor = [UIColor redColor];
        self.percentLabel.font = [UIFont systemFontOfSize:fontSize];
        [self addSubview:percentLabel];
        
    }
    
    return self;
}

-(void)setTradeMarketFrame:(YJBTradeMarketFrame *)tradeMarketFrame{

    _tradeMarketFrame = tradeMarketFrame;
    self.nameLabel.text = tradeMarketFrame.tradeMarketModel.tradeName;
    self.nameLabel.frame = tradeMarketFrame.tradeNameLabelF;
    
    self.codeLabel.text = tradeMarketFrame.tradeMarketModel.tradeCode;
    self.codeLabel.frame = tradeMarketFrame.tradeCodeLabelF;
    
    if (!tradeMarketFrame.tradeMarketModel.presentPrice) {
        self.nowPriceLabel.text = @"---";
        
    }else{
        self.nowPriceLabel.text = [NSString stringWithFormat:@"%@", tradeMarketFrame.tradeMarketModel.presentPrice];
    }
    self.nowPriceLabel.frame = tradeMarketFrame.presentPriceLabelF;
    
    if (!tradeMarketFrame.tradeMarketModel.presentCounts) {
        self.nowCountLabel.text = @"0";
        
    }else{
        self.nowCountLabel.text = [NSString stringWithFormat:@"%@",tradeMarketFrame.tradeMarketModel.presentCounts];
    }
    self.nowCountLabel.frame = tradeMarketFrame.presentCountsLabelF;
    
    if (!tradeMarketFrame.tradeMarketModel.buyCounts) {
        self.buyCountLabel.text  = @"0";
    }else{
        self.buyCountLabel.text  = [NSString stringWithFormat:@"%@", tradeMarketFrame.tradeMarketModel.buyCounts];
    }
    
    if (!tradeMarketFrame.tradeMarketModel.sellCounts) {
        self.sellCountLabel.text  = @"0";
    }else{
        self.sellCountLabel.text  =[NSString stringWithFormat:@"%@", tradeMarketFrame.tradeMarketModel.sellCounts];
    }
    
    if (!tradeMarketFrame.tradeMarketModel.buyPrice) {
        self.buyPriceLabel.text  = @"---";
    }else{
        self.buyPriceLabel.text  = [NSString stringWithFormat:@"%@",tradeMarketFrame.tradeMarketModel.buyPrice];
    }
    
    if (!tradeMarketFrame.tradeMarketModel.sellPrice) {
        self.sellPriceLabel.text  = @"---";
    }else{
        self.sellPriceLabel.text  =[NSString stringWithFormat:@"%@", tradeMarketFrame.tradeMarketModel.sellPrice];
    }
    
    self.buyPriceLabel.frame = tradeMarketFrame.buyPriceLabelF;
    
    self.sellPriceLabel.frame = tradeMarketFrame.sellPriceLabelF;
    
    self.buyCountLabel.frame = tradeMarketFrame.buyCountsLabelF;
    self.sellCountLabel.frame = tradeMarketFrame.sellCountsLabelF;
    
    if ([tradeMarketFrame.tradeMarketModel.risePercent floatValue] > 0) {
        
        float riseScale = [tradeMarketFrame.tradeMarketModel.risePercent floatValue];
        self.percentLabel.text = [NSString stringWithFormat:@"%0.2f%%",riseScale];
        self.percentLabel.textColor = KMainColor;
        
    }else if([tradeMarketFrame.tradeMarketModel.risePercent floatValue] < 0){
        
        float riseScale = [tradeMarketFrame.tradeMarketModel.risePercent floatValue];
        self.percentLabel.text = [NSString stringWithFormat:@"%0.2f%%",riseScale];
        self.percentLabel.textColor = BAD_MAIN_COLOR;
        
    }else{
        
        self.percentLabel.text = [NSString stringWithFormat:@"0%%"];
        
    }
    
    
    self.percentLabel.frame = tradeMarketFrame.risePercentLabelF;

}

@end
